package com.zjxf.controller;

import com.zjxf.base.bean.vo.VoSeller;
import com.zjxf.base.common.JSONResponse;
import com.zjxf.base.common.OperationException;
import com.zjxf.base.common.SysConst;
import com.zjxf.service.SellerService;
import com.zjxf.utils.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户接口
 *
 * @author ZhangWei
 * @date 2021/3/24/024 10:06
 */
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@Api(tags = "商家")
@RequestMapping("/seller/")
public class SellerController {

    private final SellerService sellerService;

    @ApiOperation(value = "登录")
    @PostMapping(value = "login")
    public JSONResponse login(@Valid @RequestBody VoSeller.login voSeller){
        LoginUtil.login(voSeller.getUsername(), voSeller.getPassword(), voSeller.getRemeberMe(),voSeller.getType());
        return JSONResponse.success(SysConst.LOGIN_SUCCESS);
    }

    @ApiOperation(value = "添加或修改")
    @PostMapping(value = "addOrUpdate")
    public JSONResponse addOrUpdate(@Valid @RequestBody VoSeller.addOrUpdate voSeller) throws OperationException {
        sellerService.addOrUpdate(voSeller);
        return JSONResponse.success(SysConst.SUCCESS);
    }

}
